package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/10.
 */
@HttpInlet(Conn.SIGN_GET)
public class DayDaySignGet extends BaseAsyGet<DayDaySignGet.DayDaySignEntity> {


    public DayDaySignGet(AsyCallBack<DayDaySignEntity> asyCallBack) {
        super(asyCallBack);
    }


    @Override
    protected DayDaySignEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            DayDaySignEntity dayDaySignEntity = new DayDaySignEntity();

            JSONArray bannerArray = object.optJSONArray("banner");

            for (int i = 0; i < bannerArray.length(); i++) {

                BannerEntity bannerEntity = new BannerEntity();

                JSONObject bannerObject = bannerArray.optJSONObject(i);

                bannerEntity.id = bannerObject.optString("id");
                bannerEntity.good_id = bannerObject.optString("good_id");
                bannerEntity.picurl = Conn.IMAGE_BANNER_URL + bannerObject.optString("picurl");
                bannerEntity.title = bannerObject.optString("title");
                bannerEntity.type = bannerObject.optString("type");

                dayDaySignEntity.bannerEntities.add(bannerEntity);

            }


            JSONArray scrollArray = object.optJSONArray("signList");

            for (int i = 0; i < scrollArray.length(); i++) {

                ScrollEntity scrollEntity = new ScrollEntity();

                JSONObject scrollObject = scrollArray.optJSONObject(i);

                scrollEntity.id = scrollObject.optString("id");
                scrollEntity._id = scrollObject.optString("_id");
                scrollEntity.info = scrollObject.optString("info");
                scrollEntity.money = scrollObject.optString("money");
                scrollEntity.phone = scrollObject.optString("phone");
                scrollEntity.times = scrollObject.optString("times");
                scrollEntity.type = scrollObject.optString("type");
                scrollEntity.user_id = scrollObject.optString("user_id");

                dayDaySignEntity.scrollEntities.add(scrollEntity);

            }

            JSONArray signShowArray = object.optJSONArray("showList");

            for (int i = 0; i < signShowArray.length(); i++) {

                SignShowEntity signShowEntity = new SignShowEntity();

                JSONObject signShowObject = signShowArray.optJSONObject(i);

                signShowEntity.id = signShowObject.optString("id");
                signShowEntity.is_seat = signShowObject.optString("is_seat");
                signShowEntity.picurl = Conn.IMAGE_BANNER_URL + signShowObject.optString("picurl");
                signShowEntity.place_name = signShowObject.optString("place_name");
                signShowEntity.placeid = signShowObject.optString("placeid");
                signShowEntity.start_time = signShowObject.optString("start_time");
                signShowEntity.status = signShowObject.optString("status");
                signShowEntity.title = signShowObject.optString("title");

                dayDaySignEntity.signShowEntities.add(signShowEntity);

            }


            return dayDaySignEntity;


        }

        return null;
    }

    public static class DayDaySignEntity {

        public List<BannerEntity> bannerEntities = new ArrayList<>();
        public List<ScrollEntity> scrollEntities = new ArrayList<>();
        public List<SignShowEntity> signShowEntities = new ArrayList<>();

    }

    public static class BannerEntity {


        public String id, title, picurl, type, good_id;
    }

    public static class ScrollEntity {


        public String _id, id, user_id, phone, type, money, times, info;
    }

    public static class SignShowEntity {

        public String id, title, picurl, start_time, placeid, is_seat, status, place_name;
    }


}
